from selenium.webdriver.common.by import By

from page_objects.base_page import BasePage


class LoginPage(BasePage):
    __NAME = "hogwarts"
    __PASSWORD = "test12345"
    __INPUT_NAME = (By.NAME, "username")
    __INPUT_PASSWORD = (By.NAME, "password")
    __LOGIN_CLICK = (By.XPATH, '//span[contains(text(),"登录")]')
    def login(self):
        """登录页面：用户登录"""
        # 访问登录页
        # 输入“用户名”
        self.do_find(self.__INPUT_NAME).clear()
        self.do_send_keys(self.__NAME,self.__INPUT_NAME)
        # 输入“密码”
        self.do_find(self.__INPUT_PASSWORD).clear()
        self.do_send_keys(self.__PASSWORD,self.__INPUT_PASSWORD)
        # 点击“登录”按钮
        self.do_find(self.__LOGIN_CLICK).click()
        # ==》首页
        from page_objects.home_page import HomePage
        return HomePage(self.driver)